package cnd;

/**
 * The main controller for the CND program, all calls between the three parts
 * of the program (Search, Download and GUI) go through the controller.
 * @author Marten Jacobs
 * @version 0.1
 */
public class Controller{
    SearchController searchController;
    MainWindow mainWindow;
    DownloadController downloadController;
    public Controller(){
        searchController = new SearchController(this);
        mainWindow = new MainWindow(this);
        downloadController = new DownloadController(this);
        mainWindow.setVisible(true);

        searchController.init();
    }
    /**
     * Calls the SearchController to create a search with a given query
     * @param query
     * The query given
     */
    public void addSearch(String query){
        searchController.search(query);
    }
    /**
     * Tells the searchResults JTable in the mainWindow of this Controller to
     * update
     */
    public void updateSearchResultsTable(){
        mainWindow.updateSearchResultsTable();
    }
    /**
     * Tell the searchResults JTable in the mainWindow of this Controller to
     * use the given searchResultTableModel
     * @param searchResultTableModel
     * the searchResultTableModel given
     */
    public void setSearchResultsTableModel(SearchResultTableModel searchResultTableModel){
        mainWindow.setSearchResultsTableModel(searchResultTableModel);
    }
    /**
     * Add and start a download based on a given SearchResult
     * @param searchResult
     * the SearchResult given
     */
    public void addDownload(SearchResult searchResult){
        //System.out.println(searchResult.name);
        downloadController.addDownload(searchResult);
    }
}
